import { defineStore } from "pinia";

export const useAppStore = defineStore("app", {
  state: () => ({
    userInfo: JSON.parse(localStorage.getItem("userInfo")) || null,
    unreadCount: 0,
  }),
  actions: {
    setUserInfo(userInfo) {
      this.userInfo = userInfo;
      localStorage.setItem("userInfo", JSON.stringify(userInfo));
    },
    setUnreadCount(unreadCount) {
      this.unreadCount = unreadCount;
    },
  },
  getters: {
    getUserInfo(state) {
      return state.userInfo || {};
    },
    getUnreadCount(state) {
      return state.unreadCount || 0;
    },
  },
});
